import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:city_corner/commons/tags.dart';
import 'package:city_corner/detail-page/house-desc/feature-area.dart';

import '../my-container.dart';

class HouseDesc extends StatelessWidget {
  ValueNotifier<int> _counter = ValueNotifier<int>(0);
  Map desc = {
    "title": '大石阳光单间',
    "rentType": '整租',
    "price": '2100',
    "deposit": "押二付一",
    "area": "30",
    "householdType": "1室1厅1卫",
    "floor": "中/6",
    "towards": "东南",
    "includes": ["有电梯", "配置齐全", "有阳台"]
  };

  Widget titleArea(width) {
    return Container(
        padding: EdgeInsets.only(left: 10.0, right: 10.0),
        width: width,
        child: Text('${desc["rentType"]} | ${desc["title"]}',
            style: TextStyle(fontSize: 25.0)));
  }

  Widget priceArea() {
    return MyContainer(
      child: Row(children: [
        Baseline(
            baseline: 20.0,
            baselineType: TextBaseline.ideographic,
            child: Text('${desc["price"]}/月',
                style: TextStyle(
                    textBaseline: TextBaseline.ideographic,
                    fontSize: 20.0,
                    color: Color(0xffFC783D)))),
        SizedBox(width: 5),
        Baseline(
            baseline: 20.0,
            baselineType: TextBaseline.ideographic,
            child: Text('${desc['deposit']}',
                style: TextStyle(
                    textBaseline: TextBaseline.ideographic,
                    color: Colors.grey,
                    fontSize: 12.0)))
      ]),
    );
  }

  Widget includesArea() {
    return MyContainer(
        child: Tags(
            padding: [10.0, 3.0, 10.0, 3.0],
            fontColor: 0xFF40a9ff,
            tags: desc["includes"],
            border: {"color": 0xFF40a9ff, "width": 1.0, "radius": 5.0},
            fontSize: 15.0,
            margin: {"right": 10.0}));
  }

  @override
  Widget build(BuildContext context) {
    _counter.value++;
    return ValueListenableBuilder(
      builder: (BuildContext context, int value, Widget child) {
        List<Map<String, String>> feature = [
          {'value': desc['householdType'], "label": "户型"},
          {'value': desc['area'], "label": "面积"},
          {'value': desc['floor'], "label": "楼层"},
          {'value': desc['towards'], "label": "朝向"}
        ];
        return Column(children: [
          titleArea(MediaQuery.of(context).size.width),
          priceArea(),
          FeatureArea(data: feature),
          includesArea()
        ]);
      },
      valueListenable: _counter,
    );
  }
}
